package com.intellagric.service.iftmonitor.Impl.ift_equipment;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.dao.iftmonitor.EquipmentBreakdownDao;
import com.intellagric.mapper.IftEquipmentBreakdownMapper;
import com.intellagric.module.iftmonitor.EquipmentStatusVo;
import com.intellagric.pojo.*;
import com.intellagric.service.iftmonitor.ift_equipment.EquipmentBreakdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/23
 * @DESC： 设备故障信息服务实现
 */
@Service
public class EquipmentBreakdownServiceImpl implements EquipmentBreakdownService {

    @Autowired
    private IftEquipmentBreakdownMapper equipmentBreakdownMapper;

    @Autowired
    private EquipmentBreakdownDao equipmentBreakdownDao;

    /**
     * 添加设备故障信息
     * @param equipmentBreakdown
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addEquipmentBreakdown(IftEquipmentBreakdownWithBLOBs equipmentBreakdown) {
        if (equipmentBreakdownMapper.insertSelective(equipmentBreakdown) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除设备故障信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteEquipmentBreakdown(String id) {
        if (equipmentBreakdownMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改设备故障信息
     * @param equipmentBreakdown
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editEquipmentBreakdown(IftEquipmentBreakdownWithBLOBs equipmentBreakdown) {
        if (equipmentBreakdownMapper.updateByPrimaryKeyWithBLOBs(equipmentBreakdown) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询设备故障信息
     * @param id
     * @return IftEquipmentBreakdownWithBLOBs
     */
    @Override
    public IftEquipmentBreakdownWithBLOBs getEquipmentBreakdownById(String id) {
        return equipmentBreakdownMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询设备故障信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getEquipmentBreakdownList() {
        IftEquipmentBreakdownExample equipmentBreakdownExample = new IftEquipmentBreakdownExample();
        equipmentBreakdownExample.createCriteria().andIdIsNotNull();
        List<IftEquipmentBreakdown> equipmentBreakdownList = equipmentBreakdownMapper.selectByExample(equipmentBreakdownExample);
        return LayuiDataGridResult.success().add(equipmentBreakdownList,equipmentBreakdownList.size());
    }

    /**
     * 多条件查询设备故障信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getEquipmentBreakdownListByVo(EquipmentStatusVo equipmentStatusVo) {
        List<IftEquipmentBreakdown> equipmentBreakdownList = equipmentBreakdownDao.selectEquipmentBreakdownListByVo(equipmentStatusVo);
        return LayuiDataGridResult.success().add(equipmentBreakdownList,equipmentBreakdownList.size());
    }

    /**
     * 分页查询设备故障信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getEquipmentBreakdownPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftEquipmentBreakdownExample equipmentBreakdownExample = new IftEquipmentBreakdownExample();
        equipmentBreakdownExample.createCriteria().andIdIsNotNull();
        List<IftEquipmentBreakdown> equipmentBreakdownList = equipmentBreakdownMapper.selectByExample(equipmentBreakdownExample);
        return LayuiDataGridResult.success().add(equipmentBreakdownList,this.getEquipmentBreakdownList().getCount());
    }
}
